package com.mercury.util;

import com.mercury.config.RootConfig;
import com.mercury.config.WebConfig;
import com.mercury.filter.MercuryFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

/**
 * @author ：tx
 * @description：初始化获取dispatherservlet和webapplication
 * @date ：Created in 2019/1/24 19:28
 * @modified By：
 * @version: 1.0
 */
public class MercuryInit extends AbstractAnnotationConfigDispatcherServletInitializer {  //会自动配置dispatherservlet和webApplicationContext

    @Override
    protected Class<?>[] getRootConfigClasses() { //当contextLoaderListener加载webApplicationContext时   spring上下文
        return new Class[]{RootConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() { //当dispatherservlet开始加载容器时 这里的作用就是表明要加载这个配置文件下的bean   spring mvc上下文
        return new Class[]{WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    
    /**
     * @author tx
     * @description  自动装配fileter  什么路径都会调用filter
     * @date  2019/2/27 11:00
     * @param  * @Param: 
     * @return javax.servlet.Filter[]
    **/
    /*@Override
    protected Filter[] getServletFilters() {
        return new Filter[]{new MercuryFilter()};
    }*/

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        super.customizeRegistration(registration);
        registration.setMultipartConfig(new MultipartConfigElement("E:\\files\\spring"));
    }
}
